package com.yun.mult;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * Created by lsy
 * on 2020/9/18 15:10.
 */
public class TestCountDown {
    private static volatile int i = 0;

    public static void increase() {
        i++;
    }

    public static void main(String[] args) throws InterruptedException {
        CountDownLatch latch = new CountDownLatch(10);
        ExecutorService executor = Executors.newFixedThreadPool(10);
        for (int j = 0; j < 10; j++) {

            executor.submit(() -> {
                latch.countDown();
                for (int i = 0; i < 1000; i++) {
                    increase();
                }
            });
        }

        latch.await();
        executor.shutdown();
        System.out.println("complete i :" + i);
    }
}
